package com.hopu.haogoumall.db.mapper;

import com.hopu.haogoumall.db.module.HaogoumallRegion;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.UpdateProvider;
import org.apache.ibatis.type.JdbcType;

public interface HaogoumallRegionMapper {
    @Delete({
        "delete from haogoumall_region",
        "where region_id = #{regionId,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(Integer regionId);

    @Insert({
        "insert into haogoumall_region (region_id, region_pid, ",
        "region_name, region_type, ",
        "region_code)",
        "values (#{regionId,jdbcType=INTEGER}, #{regionPid,jdbcType=INTEGER}, ",
        "#{regionName,jdbcType=VARCHAR}, #{regionType,jdbcType=TINYINT}, ",
        "#{regionCode,jdbcType=INTEGER})"
    })
    int insert(HaogoumallRegion record);

    @InsertProvider(type=HaogoumallRegionSqlProvider.class, method="insertSelective")
    int insertSelective(HaogoumallRegion record);

    @Select({
        "select",
        "region_id, region_pid, region_name, region_type, region_code",
        "from haogoumall_region",
        "where region_id = #{regionId,jdbcType=INTEGER}"
    })
    @Results({
        @Result(column="region_id", property="regionId", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="region_pid", property="regionPid", jdbcType=JdbcType.INTEGER),
        @Result(column="region_name", property="regionName", jdbcType=JdbcType.VARCHAR),
        @Result(column="region_type", property="regionType", jdbcType=JdbcType.TINYINT),
        @Result(column="region_code", property="regionCode", jdbcType=JdbcType.INTEGER)
    })
    HaogoumallRegion selectByPrimaryKey(Integer regionId);

    @UpdateProvider(type=HaogoumallRegionSqlProvider.class, method="updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(HaogoumallRegion record);

    @Update({
        "update haogoumall_region",
        "set region_pid = #{regionPid,jdbcType=INTEGER},",
          "region_name = #{regionName,jdbcType=VARCHAR},",
          "region_type = #{regionType,jdbcType=TINYINT},",
          "region_code = #{regionCode,jdbcType=INTEGER}",
        "where region_id = #{regionId,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(HaogoumallRegion record);
}